package edu.ccut.saturn.component.loader.data;

import java.util.List;

import org.dom4j.Element;

import edu.ccut.saturn.component.ISaturnDataSqlItemInfo;
import edu.ccut.saturn.component.impl.sql.IsEqualItemInfo;

public class IsEqualElementLoader extends AbstractSqlItemInfoLoader {

	@Override
	public ISaturnDataSqlItemInfo loadSqlItemInfo(Object element)
			throws Exception {

		if (element instanceof Element) {
			String prepend = ((Element) element)
					.attributeValue(NODE_KEY_PREPEND);

			String property = ((Element) element)
					.attributeValue(NODE_KEY_PROPERTY);

			String compared = ((Element) element)
					.attributeValue(NODE_KEY_ISEQUAL_COMPAREVALUE);

			boolean isProperty = false;

			if (compared == null) {
				compared = ((Element) element)
						.attributeValue(NODE_KEY_ISEQUAL_COMPAREPROPERTY);

				isProperty = true;
			}

			IsEqualItemInfo isEqualItemInfo = new IsEqualItemInfo(prepend,
					property, compared, isProperty);

			if (((Element) element).content().size() > 0) {
				List<ISaturnDataSqlItemInfo> sqlItemInfos = getSqlItemInfos(((Element) element)
						.content());

				isEqualItemInfo.setSubSqlItemInfos(sqlItemInfos);
			}
			return isEqualItemInfo;
		}
		return null;
	}

}
